package com.shayne.controller.screenmain;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;

import com.shayne.log.SMLog;
import com.shayne.services.ScreenMainServices;
import com.shayne.view.domains.ScreenMain;
import com.shayne.views.ScreenMainView;

public class SumBtnController implements EventHandler<ActionEvent> {
	
	private ScreenMainView screenMainView;
	private ScreenMainServices screenMainServices;

	public SumBtnController(ScreenMainView screenMainView) {
		this.screenMainView = screenMainView;
		screenMainServices = new ScreenMainServices();
	}

	@Override
	public void handle(ActionEvent event) {
		
		ScreenMain screenMain = screenMainView.getScreenMainRender().getScreenMain();
		SMLog.log("Get number 1 from textfield...");
		int number1 = Integer.parseInt(screenMain.getNumberOne().getText().trim());
		SMLog.log("Get number 2 from textfield...");
		int number2 = Integer.parseInt(screenMain.getNumberTwo().getText().trim());
		int sum = screenMainServices.sum(number1, number2);
		
//		send response to view
		SMLog.log("Send "+ sum+" to sum label in screen main view.");
		screenMain.getSumLbl().setText("Sum two number: " + sum);
	}
	
	public ScreenMainView getScreenMainView() {
		return screenMainView;
	}

	public void setScreenMain(ScreenMainView screenMainView) {
		this.screenMainView = screenMainView;
	}
	
}
